﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.FieldLookup", ServerTypeId="{ee47ff61-3260-43a9-be22-829a1fa85b44}")]
    public class FieldLookup : Field
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FieldLookup(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                switch (peekedName)
                {
                    case "LookupWebId":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["LookupWebId"] = reader.ReadGuid();
                        return flag;

                    case "LookupList":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["LookupList"] = reader.ReadString();
                        return flag;

                    case "LookupField":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["LookupField"] = reader.ReadString();
                        return flag;

                    case "RelationshipDeleteBehavior":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["RelationshipDeleteBehavior"] = reader.ReadEnum<RelationshipDeleteBehaviorType>();
                        return flag;

                    case "IsRelationship":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["IsRelationship"] = reader.ReadBoolean();
                        return flag;

                    case "AllowMultipleValues":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["AllowMultipleValues"] = reader.ReadBoolean();
                        return flag;

                    case "PrimaryFieldId":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["PrimaryFieldId"] = reader.ReadString();
                        return flag;
                }
            }
            return flag;
        }

        [Remote]
        public bool AllowMultipleValues
        {
            get
            {
                base.CheckUninitializedProperty("AllowMultipleValues");
                return (bool) base.ObjectData.Properties["AllowMultipleValues"];
            }
            set
            {
                base.ObjectData.Properties["AllowMultipleValues"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "AllowMultipleValues", value));
                }
            }
        }

        [Remote]
        public bool IsRelationship
        {
            get
            {
                base.CheckUninitializedProperty("IsRelationship");
                return (bool) base.ObjectData.Properties["IsRelationship"];
            }
            set
            {
                base.ObjectData.Properties["IsRelationship"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "IsRelationship", value));
                }
            }
        }

        [Remote]
        public string LookupField
        {
            get
            {
                base.CheckUninitializedProperty("LookupField");
                return (string) base.ObjectData.Properties["LookupField"];
            }
            set
            {
                base.ObjectData.Properties["LookupField"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "LookupField", value));
                }
            }
        }

        [Remote]
        public string LookupList
        {
            get
            {
                base.CheckUninitializedProperty("LookupList");
                return (string) base.ObjectData.Properties["LookupList"];
            }
            set
            {
                base.ObjectData.Properties["LookupList"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "LookupList", value));
                }
            }
        }

        [Remote]
        public Guid LookupWebId
        {
            get
            {
                base.CheckUninitializedProperty("LookupWebId");
                return (Guid) base.ObjectData.Properties["LookupWebId"];
            }
            set
            {
                base.ObjectData.Properties["LookupWebId"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "LookupWebId", value));
                }
            }
        }

        [Remote]
        public string PrimaryFieldId
        {
            get
            {
                base.CheckUninitializedProperty("PrimaryFieldId");
                return (string) base.ObjectData.Properties["PrimaryFieldId"];
            }
            set
            {
                base.ObjectData.Properties["PrimaryFieldId"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "PrimaryFieldId", value));
                }
            }
        }

        [Remote]
        public RelationshipDeleteBehaviorType RelationshipDeleteBehavior
        {
            get
            {
                base.CheckUninitializedProperty("RelationshipDeleteBehavior");
                return (RelationshipDeleteBehaviorType) base.ObjectData.Properties["RelationshipDeleteBehavior"];
            }
            set
            {
                base.ObjectData.Properties["RelationshipDeleteBehavior"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "RelationshipDeleteBehavior", value));
                }
            }
        }
    }
}

